FIUMAPS.URLParameters = function() {
    var intGeoCount = 0;
    /*
    FIUMAPS.URLParameters.GenerateURL
    OPERATION
    DESCRIPTION:        this method will generate a URL parameter string from the map 
    that is currently being viewed.
    INPUT PARAMETERS:   campus_id: int, mapLayerItem: mapLayers, myLocationsItem: myLocations
    OUTPUT:             ?cid=9&bids=9,99,999&sids=9,99,999&lids=9,99,999&lat=25.756957&lat=-80.376062&zl=14&mt=Hyb
    OUTPUT DESCRIPTION
    cid:        campus id
    bids:       building id(s): A comma delimited list of highlighted buildings
    sids:       service id(s) A comma delimited list of highlighted services
    lids:       layer id(s) A comma delimited list of visible layers
    lat:        latitude: where center should be. (center at)
    lng:        longitued: where the center should be. (center at)
    zl:         current zoom level.
    mt:         current Map Type. Use FIUMAPS.GMapTypes to lookup.
    */
    this.GenerateURL = function(parametersOnly) {

        var strURL = ""; // return string 
        // add cid parameter and value to URL string
        strURL = "?cid=" + FIUMAPS.CampusInfo.getCurrentCampusID();
        // add bids and sids parameters and values to URL string
        strURL += get_bidssidsString();
        // add lids parameter and values to URL string
        strURL += "&lids=" + mymapLayers.getVisibleLayerIDs();
        // add lat parameter and value to URL string.
        strURL += "&lat=" + gmap.getCenter().lat();
        // add lng parameter and value to URL string.
        strURL += "&lng=" + gmap.getCenter().lng();
        // add zl parameter and value to URL string.
        strURL += "&zl=" + gmap.getZoom();
        // add mt parameter and value to URL string.
        strURL += "&mt=" + gmap.getCurrentMapType().getName();

        var result;
        // parameters only will only give you the ? and beyond.
        if (!parametersOnly) {
            var URLPath = window.location.href;
            if (URLPath.indexOf("?") > -1) URLPath = URLPath.substring(URLPath.indexOf("?"), 0);
            strURL = URLPath + strURL;
        }
        return strURL;
    };
    this.LoadURL = function() {
        //go to campus specified in URL Parameter.
        FIUMAPS.CampusInfo.goToCampusByID(URLDecode(getQuerystring('cid')));
        // If mapType Present, set.
        if (URLDecode(getQuerystring('mt'))) {
            switch (URLDecode(getQuerystring('mt'))) {
                case 'Map':
                    gmap.setMapType(G_NORMAL_MAP);
                    break;
                case 'Hybrid':
                    gmap.setMapType(G_HYBRID_MAP);
                    break;
                case 'Satellite':
                    gmap.setMapType(G_SATELLITE_MAP);
                    break;
                default:
                    gmap.setMapType(G_NORMAL_MAP);
            }
        }
        // If coordinates are present, load them.
        if (URLDecode(getQuerystring('lat')) && URLDecode(getQuerystring('lng')) && URLDecode(getQuerystring('zl'))) {
            //gmap.panTo(new GLatLng(URLDecode(getQuerystring('lat')),URLDecode(getQuerystring('lng'))));
            gmap.setCenter(new GLatLng(URLDecode(getQuerystring('lat')), URLDecode(getQuerystring('lng'))), parseInt(URLDecode(getQuerystring('zl'))));
        }
        //if there are any LayerIDs in URL, load them.
        if (URLDecode(getQuerystring('lids'))) {
            mymapLayers.setDefaultVisibilityIDs(URLDecode(getQuerystring('lids')));
        }
        //if there are any building Ids in URL, load them.
        if (URLDecode(getQuerystring('bids'))) {
            loadBuildings(URLDecode(getQuerystring('bids')));
        }
        //if there are any service Ids in URL, load them.
        if (URLDecode(getQuerystring('sids'))) {
            loadServices(URLDecode(getQuerystring('sids')));
        }

        //console.debug(window.location.href);
    };
    function loadBuildings(building_ids) {
        intGeoCount += building_ids.split(",").length;

        // Query Task
        var qtask = new esri.arcgis.gmaps.QueryTask("http://maps.fiu.edu/arcgis/rest/services/FIUCampusMaps/ServicesNBuildings/MapServer/1");
        // Query
        var query = new esri.arcgis.gmaps.Query();
        // set query parameters. 
        query.returnGeometry = true;
        query.where = "BUILDING_ID IN (" + building_ids + ")";
        query.outFields = ["BUILDING_ID", "NAME", "CODE", "DESCRIPTION", "CAMPUS_ID", "CAMPUS_CODE"];
        // execute query task
        qtask.execute(query, false, loadBuildings_CallBack);
    }
    function loadBuildings_CallBack(fset) {
        if (fset !== null) {
            // clear map overlays
            //ClearOverlays();    

            var results = fset.features, attributes, geometry;
            //loop through features  
            for (var i = 0; i < results.length; i++) {
                attributes = results[i].attributes;
                geometry = results[i].geometry;

                for (var z = 0; z < geometry.length; z++) { // Feature.geometry is an array of GPolygon/GPolyline/GMarker
                    var geom = geometry[z];
                    // add event listener to geometries
                    GEvent.addListener(geom, "click", GEvent.callbackArgs(geom, PolyonClickFunc, attributes, true));
                    // add geometry overlay to map.
                    AddOverlay(geom, attributes);
                    // add to myLocations                   
                    mymapLocations.addtoMyLocations(geom, attributes);
                }
            }
            if (mymapLocations.getMyLocations().length == intGeoCount) {
                $('myLocationsHeader').fireEvent('click');
            }
        }
    }
    function loadServices(service_ids) {
        intGeoCount += service_ids.split(",").length;
        // Query Task
        var qtask = new esri.arcgis.gmaps.QueryTask("http://maps.fiu.edu/arcgis/rest/services/FIUCampusMaps/ServicesNBuildings/MapServer/0");
        var query = new esri.arcgis.gmaps.Query();
        // set query parameters. 
        query.returnGeometry = true;
        query.where = "OBJECTID IN (" + service_ids + ")";
        query.outFields = ["OBJECTID", "SERVICE_ID", "NAME", "DESCRIPTION", "FLOOR", "ROOM_NUMBER", "CATEGORY_NAME", "BUILDING_CODE", "BUILDING_NAME", "BUILDING_ID", "CAMPUS_ID", "CAMPUS_CODE", "CAMPUS_NAME"];
        // execute query task
        qtask.execute(query, false, loadServices_CallBack);
    }
    function loadServices_CallBack(fset) {
        if (fset !== null) {
            // clear map overlays
            //ClearOverlays();    

            var results = fset.features, attributes, geometry;
            //loop through features  
            for (var i = 0; i < results.length; i++) {
                attributes = results[i].attributes;
                geometry = results[i].geometry;

                for (var z = 0; z < geometry.length; z++) { // Feature.geometry is an array of GPolygon/GPolyline/GMarker
                    var geom = geometry[z];
                    // add event listener to geometries
                    GEvent.addListener(geom, "click", GEvent.callbackArgs(geom, MarkeronMouseOverFunc, attributes, true));
                    // add geometry overlay to map.
                    AddOverlay(geom, attributes);
                    // add to myLocations
                    mymapLocations.addtoMyLocations(geom, attributes);
                }
            }
            if (mymapLocations.getMyLocations().length == intGeoCount) {
                $('myLocationsHeader').fireEvent('click');
            }
        }
    }
    function get_bidssidsString() {

        if (FIUMAPS.Overlays.Data) {
            var arrBids = new Array();
            var arrSids = new Array();
            var attributes;
            // loop through myLocations extracting IDs.
            for (var z = 0; z < FIUMAPS.Overlays.Data.length; z++) {
                attributes = FIUMAPS.Overlays.Data[z][1];

                if (!attributes.SERVICE_ID) {//item is a building
                    //make sure building ID is not already in there.
                    if (arrBids.indexOf(attributes.BUILDING_ID) == -1) {
                        arrBids.push(attributes.BUILDING_ID);
                    }
                } else {//item is a Service
                    arrSids.push(attributes.OBJECTID);
                }
            }
            var strReturnString = "";
            if (arrBids.length > 0) { strReturnString += "&bids=" + arrBids.toString(); }
            if (arrSids.length > 0) { strReturnString += "&sids=" + arrSids.toString(); }
            return strReturnString;
        } else {
            return "";
        }
    }
}